package cn.jy.map.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;

import cn.jy.map.domain.PlasmaResult;
import cn.jy.map.domain.ProviderBaseInfo;
import cn.jy.map.jedis.JedisClient;
import cn.jy.map.mapper.GjzLcMapper;
import cn.jy.map.mapper.PlasmaCountMapper;
import cn.jy.map.service.PlasmaStatisticsService;
import cn.jy.map.utils.DateUtils;
import cn.jy.map.utils.FrequencyResult;
import cn.jy.map.utils.Results;
import cn.jy.map.utils.StringUtil;
import cn.jy.map.utils.ValueUtiles;
import cn.jy.nvr.datasource.DataSourceConst;
import cn.jy.nvr.datasource.DataSourceContextHolder;

/**
 * @author XiongJing
 * @version 1.0
 * @date 2018年7月8日 上午12:07:52 类说明:统计血浆量的service
 */
@Service("plasmaStatisticsService")
public class PlasmaStatisticsServiceImpl implements PlasmaStatisticsService {

	@Autowired
	private GjzLcMapper gjzLcMapper;
	Logger logger = Logger.getLogger(PlasmaStatisticsServiceImpl.class);

	@Autowired
	private PlasmaCountMapper plasmaCountMapper;

	@Autowired
	private JedisClient jedisClient;

	/**
	 * 按月统计血浆量的方法
	 */
	@Override
	public Map<String, Integer> pulpQuantityDetailMonth() throws Exception {
		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		Map<String, Integer> plasmas = new HashMap<String, Integer>();
		// Date startTime = DateUtils.getLastYear(new Date());//17年的数据测试接口用
		Date startTime = DateUtils.getYearFirstDayOfTheFrstMonth(new Date());
		Date endTime = DateUtils.getLastDayOfTheMonth(startTime);
		int monthPlasmaGross = gjzLcMapper.pulpQuantityDetailMonth(DateUtils.getSimpleDateFormat(startTime),
				DateUtils.getSimpleDateFormat(endTime));
		plasmas.put("1月的总量", monthPlasmaGross);
		logger.info("1月的总浆量" + "===============>>" + monthPlasmaGross);
		// 第二个月的总量
		Date startTime2 = DateUtils.getNextDay(endTime);
		Date endTime2 = DateUtils.getLastDayOfTheMonth(startTime2);
		plasmas.put("2月的总量", getMonthPlasmaGross(startTime2, endTime2));
		logger.info("2月的总浆量" + "===============>>" + getMonthPlasmaGross(startTime2, endTime2));
		// 第三个月的总量
		Date startTime3 = DateUtils.getNextDay(endTime2);
		Date endTime3 = DateUtils.getLastDayOfTheMonth(startTime3);
		plasmas.put("3月的总量", getMonthPlasmaGross(startTime3, endTime3));
		logger.info("3月的总浆量" + "===============>>" + getMonthPlasmaGross(startTime3, endTime3));
		// 第4个月的总量
		Date startTime4 = DateUtils.getNextDay(endTime3);
		Date endTime4 = DateUtils.getLastDayOfTheMonth(startTime4);
		plasmas.put("4月的总量", getMonthPlasmaGross(startTime4, endTime4));
		logger.info("4月的总浆量" + "===============>>" + getMonthPlasmaGross(startTime4, endTime4));
		// 第5个月的总量
		Date startTime5 = DateUtils.getNextDay(endTime4);
		Date endTime5 = DateUtils.getLastDayOfTheMonth(startTime5);
		plasmas.put("5月的总量", getMonthPlasmaGross(startTime5, endTime5));
		logger.info("5月的总浆量" + "===============>>" + getMonthPlasmaGross(startTime5, endTime5));
		// 第6个月的总量
		Date startTime6 = DateUtils.getNextDay(endTime5);
		Date endTime6 = DateUtils.getLastDayOfTheMonth(startTime6);
		plasmas.put("6月的总量", getMonthPlasmaGross(startTime6, endTime6));
		logger.info("6月的总浆量" + "===============>>" + getMonthPlasmaGross(startTime6, endTime6));
		// 第7个月的总量
		Date startTime7 = DateUtils.getNextDay(endTime6);
		Date endTime7 = DateUtils.getLastDayOfTheMonth(startTime7);
		plasmas.put("7月的总量", getMonthPlasmaGross(startTime7, endTime7));
		logger.info("7月的总浆量" + "===============>>" + getMonthPlasmaGross(startTime7, endTime7));
		// 第8个月的总量
		Date startTime8 = DateUtils.getNextDay(endTime7);
		Date endTime8 = DateUtils.getLastDayOfTheMonth(startTime8);
		plasmas.put("8月的总量", getMonthPlasmaGross(startTime8, endTime8));
		logger.info("8月的总浆量" + "===============>>" + getMonthPlasmaGross(startTime8, endTime8));
		// 第9个月的总量
		Date startTime9 = DateUtils.getNextDay(endTime8);
		Date endTime9 = DateUtils.getLastDayOfTheMonth(startTime9);
		plasmas.put("9月的总量", getMonthPlasmaGross(startTime9, endTime9));
		logger.info("9月的总浆量" + "===============>>" + getMonthPlasmaGross(startTime9, endTime9));
		// 第10个月的总量
		Date startTime10 = DateUtils.getNextDay(endTime9);
		Date endTime10 = DateUtils.getLastDayOfTheMonth(startTime10);
		plasmas.put("10月的总量", getMonthPlasmaGross(startTime10, endTime10));
		logger.info("10月的总浆量" + "===============>>" + getMonthPlasmaGross(startTime10, endTime10));
		// 第11个月的总量
		Date startTime11 = DateUtils.getNextDay(endTime10);
		Date endTime11 = DateUtils.getLastDayOfTheMonth(startTime11);
		plasmas.put("11月的总量", getMonthPlasmaGross(startTime11, endTime11));
		logger.info("11月的总浆量" + "===============>>" + getMonthPlasmaGross(startTime11, endTime11));
		// 第11个月的总量
		Date startTime12 = DateUtils.getNextDay(endTime11);
		Date endTime12 = DateUtils.getLastDayOfTheMonth(startTime12);
		plasmas.put("12月的总量", getMonthPlasmaGross(startTime12, endTime12));
		logger.info("12月的总浆量" + "===============>>" + getMonthPlasmaGross(startTime12, endTime12));

		return plasmas;
	}

	/**
	 * 按天统计血浆量的方法
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Map<String, PlasmaResult> getRoundsOfStatistical2() throws Exception {
		Map<String, PlasmaResult> result = new HashMap<String, PlasmaResult>();
		// 先查询缓存
		String JSON2 = jedisClient.get("JSON2");
		if (StringUtil.isNotNull(JSON2)) {
			result = (Map<String, PlasmaResult>) JSONObject.parse(JSON2);
			return result;
		}
		result = insertRoundsOfStatistical();
		return result;
	}

	/**
	 * 得到轮次的统计数
	 * 
	 * @return
	 */
	private PlasmaResult getRotationStatistics2(Date statTime, Date endTime) throws Exception {
		PlasmaResult plasma = new PlasmaResult();
		// 一个月的总量
		Map<String, Integer> countRoundMonth = new HashMap<String, Integer>();
		// 每轮每天的总量
		Map<String, Results> roundCountDay = new HashMap<String, Results>();
		// 每轮血浆的总量
		Integer eachRoundTotal = gjzLcMapper.getEachRoundTotal(DateUtils.getSimpleDateFormat(statTime),
				DateUtils.getSimpleDateFormat(endTime));
		countRoundMonth.put("eachRoundTotal", eachRoundTotal);
		for (int i = 0; i < 14; i++) {
			Results result = new Results();
			String date = DateUtils.getSimpleDateFormat(DateUtils.getRoundTime(statTime, i));
			Integer dayPlasmaGross = gjzLcMapper.pulpQuantityDetailRound(date);
			result.setDate(date);
			result.setCount(dayPlasmaGross);
			// 每轮每天血浆的总量
			roundCountDay.put("day" + String.valueOf(i + 1), result);
		}
		plasma.setRoundCountDay(roundCountDay);
		plasma.setCountRoundMonth(countRoundMonth);
		return plasma;
	}

	// 血浆月总量的统计
	private int getMonthPlasmaGross(Date startTime, Date endTime) {

		return gjzLcMapper.pulpQuantityDetailMonth(DateUtils.getSimpleDateFormat(startTime),
				DateUtils.getSimpleDateFormat(endTime));
	}

	/**
	 * 采浆频次的统计方法
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Map<String, Map<String, String>> getCollectPlasmaFrequency() throws Exception {
		Map<String, Map<String, String>> result = new HashMap<String, Map<String, String>>();
		// 先查询缓存
		String JSON = jedisClient.get("JSON");
		if (StringUtil.isNotNull(JSON)) {
			result = (Map<String, Map<String, String>>) JSONObject.parse(JSON);
			return result;
		}
		for (int i = 0; i <= 11; i++) {
			String endTime18 = DateUtils.getMonthLastDay(new Date(), 0, i);
			result.put(String.valueOf(i + 1) + "month", getCJFrequencyCount(endTime18));
		}
		// 存入缓存
		jedisClient.set("JSON", JSONObject.toJSONString(result));
		return result;
	}

	/**
	 * 采浆频次统计
	 * 
	 * @return
	 */
	public Map<String, String> getCJFrequencyCount(String endTime18) {
		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		Map<String, String> result = new HashMap<String, String>();
		Date date = new Date();
		// 2016-01-01
		String startTime16 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -2, 0, 1);
		// 2016-12-31
		String endTime16 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -2, 11, 31);
		// 2017-01-01
		String startTime17 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -1, 0, 1);
		// 2017-12-31
		String endTime17 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -1, 11, 31);
		// 2018-01-01
		String startTime18 = DateUtils.getAnyDayAnyYearAnyMonthString(date, 0, 0, 1);
		System.err.println("时间===" + startTime16 + "时间===" + endTime16 + "时间===" + startTime17 + "时间===" + startTime18);
		// 16年新浆员年度统计
		int newPlasma = plasmaCountMapper.getNewPlasmaCount(startTime16, endTime16);
		result.put("FZRS16", String.valueOf(newPlasma));
		// 16年新浆员在17年进站
		int stand1 = plasmaCountMapper.getNewPlasmaJZCount(startTime16, endTime16, startTime17, endTime17);
		result.put("JZRS17", String.valueOf(stand1));
		// 16年新浆员在18年进站人数
		int stand2 = plasmaCountMapper.getNewPlasmaJZCount(startTime16, endTime16, startTime18, endTime18);
		result.put("JZRS18", String.valueOf(stand2));
		// 进站率
		String JZFrequency = DateUtils.getPercentage(stand2, newPlasma);
		result.put("JZL", JZFrequency);
		// 16年新浆员在18年浆量统计
		int JLCount1 = plasmaCountMapper.getJLCount(startTime16, endTime16, startTime18, endTime18);
		result.put("CJSL18", String.valueOf(JLCount1));
		// 16年新浆员在18年的采浆频次
		String frequency1 = DateUtils.getDigital(JLCount1, stand2);
		result.put("CJPC1", frequency1);
		// ================================2017年新浆员===========================================
		int newPlasma2 = plasmaCountMapper.getNewPlasmaCount(startTime17, endTime17);
		result.put("QNFZRS", String.valueOf(newPlasma2));
		// 17年新浆员在18年进站人数统计
		int stand3 = plasmaCountMapper.getNewPlasmaJZCount(startTime17, endTime17, startTime18, endTime18);
		result.put("JZRS182", String.valueOf(stand3));
		// 进站率
		String JZFrequency2 = DateUtils.getPercentage(stand3, newPlasma2);
		result.put("JZL2", String.valueOf(JZFrequency2));
		// 17年新浆员在18年浆量统计
		int JLCount2 = plasmaCountMapper.getJLCount(startTime17, endTime17, startTime18, endTime18);
		result.put("CJSL2", String.valueOf(JLCount2));
		// 16年新浆员在18年的采浆频次
		String frequency2 = DateUtils.getDigital(JLCount2, stand3);
		result.put("CJPC2", frequency2);
		// ===================================进站浆员人数（不含2018年新浆员）=================================
		// 2017年进站人数
		int stand4 = plasmaCountMapper.getBeforeJLCount(endTime16, startTime17, endTime17);
		result.put("JZRS172", String.valueOf(stand4));
		// 2017年底前注册总人数
		int newPlasma3 = plasmaCountMapper.getBeforeJYCount(endTime17);

		result.put("ZCZRS17", String.valueOf(newPlasma3));
		// 2016年底前注册2018年进站人数
		int stand5 = plasmaCountMapper.getFormeryearsJYJZCount(endTime16, startTime18, endTime18);
		result.put("ZC16JZ18", String.valueOf(stand5));
		// 进站率
		String JZFrequency3 = DateUtils.getPercentage(stand5, stand4);
		result.put("JZL3", JZFrequency3);
		// 复苏的浆员(2016年底注册2018年恢复采浆人数)
		// int RecoveryJY = plasmaCountMapper.getRecoveryJY(ProviderNo, startTime18,
		// endTime18);
		// 17年底注册在18年进站人数
		int stand6 = plasmaCountMapper.getdCurrentYearIntoStation(endTime17, startTime18, endTime18);
		result.put("ZC17JZ18", String.valueOf(stand6));
		String a = DateUtils.getPercentage(stand6, newPlasma3);
		result.put("JZL6", a);
		// 16年前注册17年未献浆18年复苏的浆员
		int RecoveryJY = stand6 - stand5;
		result.put("FSRS18", String.valueOf(RecoveryJY));
		String stand7 = DateUtils.getPercentage(RecoveryJY, stand6);
		// 进站率
		result.put("JZL4", String.valueOf(stand7));
		// 17年底注册在2018年采浆数量
		int plasmaCount = plasmaCountMapper.getPlasmaCount(endTime17, startTime18, endTime18);
		result.put("CJZL18", String.valueOf(plasmaCount));
		String frequency3 = DateUtils.getDigital(plasmaCount, stand6);
		result.put("CJPC4", frequency3);
		// ================================2018年新浆员发展人数=============================================
		// 新浆员的采浆总数量
		int JLCount4 = plasmaCountMapper.getJLCount(startTime18, endTime18, startTime18, endTime18);
		result.put("CJSL182", String.valueOf(JLCount4));
		// 18年发展的新浆员
		int newPlasma4 = plasmaCountMapper.getNewPlasmaCount(startTime18, endTime18);
		result.put("RS18", String.valueOf(newPlasma4));
		String frequency4 = DateUtils.getDigital(JLCount4, newPlasma4);
		result.put("CJPC5", frequency4);
		// ====================采浆总数================================
		// 袋数
		int dai = plasmaCountMapper.getPlasmaNumberBags(startTime18, endTime18);
		result.put("dai", String.valueOf(dai));
		String dun = DateUtils.getDigital((dai * 0.6), 1000);
		result.put("dun", String.valueOf(dun));
		return result;
	}

	@Override
	public void insertCollectPlasmaFrequency() throws Exception {
		Map<String, Map<String, String>> result = new HashMap<String, Map<String, String>>();
		for (int i = 0; i <= 11; i++) {
			String endTime18 = DateUtils.getMonthLastDay(new Date(), 0, i);
			result.put(String.valueOf(i + 1) + "month", getCJFrequencyCount(endTime18));
		}
		// 存入缓存
		jedisClient.set("JSON", JSONObject.toJSONString(result));
	}

	@Override
	public Map<String, PlasmaResult> insertRoundsOfStatistical() throws Exception {

		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		PlasmaResult plasma = new PlasmaResult();
		// 一个月的总量
		Map<String, Integer> countRoundMonth = new HashMap<String, Integer>();
		// 每轮每天的总量
		Map<String, Results> roundCountDay = new HashMap<String, Results>();
		// Map<String, PlasmaResult> maps = MapUtils.resultMap;
		Map<String, PlasmaResult> maps = new HashMap<String, PlasmaResult>();
		// Date startTime = DateUtils.getLastYear(new Date());//17年数据测试接口用
		Date startTime = DateUtils.getYearFirstDayOfTheFrstMonth(new Date());
		Date endTime = DateUtils.getNextRound(startTime, 13);
		maps.put("round1", getRotationStatistics2(startTime, endTime));

		// 第二轮
		// 得到第二轮的初始时间
		Date startTime2 = DateUtils.getNextDay(endTime);
		// 第二轮次的结束时间
		Date endTime2 = DateUtils.getRoundEndTime(startTime2);
		maps.put("round2", getRotationStatistics2(startTime2, endTime2));

		// 第三轮次
		Date startTime3 = DateUtils.getNextDay(endTime2);
		Date endTime3 = DateUtils.getRoundEndTime(startTime3);
		maps.put("round3", getRotationStatistics2(startTime3, endTime3));

		// 第四轮次
		Date startTime4 = DateUtils.getNextDay(endTime3);
		Date endTime4 = DateUtils.getRoundEndTime(startTime4);
		maps.put("round4", getRotationStatistics2(startTime4, endTime4));

		// 第五轮次
		Date startTime5 = DateUtils.getNextDay(endTime4);
		Date endTime5 = DateUtils.getRoundEndTime(startTime5);
		maps.put("round5", getRotationStatistics2(startTime5, endTime5));
		// 第六轮次
		Date startTime6 = DateUtils.getNextDay(endTime5);
		Date endTime6 = DateUtils.getRoundEndTime(startTime6);
		maps.put("round6", getRotationStatistics2(startTime6, endTime6));
		// 第七轮次
		Date startTime7 = DateUtils.getNextDay(endTime6);
		Date endTime7 = DateUtils.getRoundEndTime(startTime7);
		maps.put("round7", getRotationStatistics2(startTime7, endTime7));
		// 第8轮次
		Date startTime8 = DateUtils.getNextDay(endTime7);
		Date endTime8 = DateUtils.getRoundEndTime(startTime8);
		maps.put("round8", getRotationStatistics2(startTime8, endTime8));
		// 第9轮次
		Date startTime9 = DateUtils.getNextDay(endTime8);
		Date endTime9 = DateUtils.getRoundEndTime(startTime9);
		maps.put("round9", getRotationStatistics2(startTime9, endTime9));
		// 第10轮次
		Date startTime10 = DateUtils.getNextDay(endTime9);
		Date endTime10 = DateUtils.getRoundEndTime(startTime10);
		maps.put("round10", getRotationStatistics2(startTime10, endTime10));
		// 第11轮次
		Date startTime11 = DateUtils.getNextDay(endTime10);
		Date endTime11 = DateUtils.getRoundEndTime(startTime11);
		maps.put("round11", getRotationStatistics2(startTime11, endTime11));
		// 第12轮次
		Date startTime12 = DateUtils.getNextDay(endTime11);
		Date endTime12 = DateUtils.getRoundEndTime(startTime12);
		maps.put("round12", getRotationStatistics2(startTime12, endTime12));
		// 第13轮次
		Date startTime13 = DateUtils.getNextDay(endTime12);
		Date endTime13 = DateUtils.getRoundEndTime(startTime13);
		maps.put("round13", getRotationStatistics2(startTime13, endTime13));
		// 第14轮次
		Date startTime14 = DateUtils.getNextDay(endTime13);
		Date endTime14 = DateUtils.getRoundEndTime(startTime14);
		maps.put("round14", getRotationStatistics2(startTime14, endTime14));
		// 第15轮次
		Date startTime15 = DateUtils.getNextDay(endTime14);
		Date endTime15 = DateUtils.getRoundEndTime(startTime15);
		maps.put("round15", getRotationStatistics2(startTime15, endTime15));
		// 第16轮次
		Date startTime16 = DateUtils.getNextDay(endTime15);
		Date endTime16 = DateUtils.getRoundEndTime(startTime16);
		maps.put("round16", getRotationStatistics2(startTime16, endTime16));
		;
		// 第17轮次
		Date startTime17 = DateUtils.getNextDay(endTime16);
		Date endTime17 = DateUtils.getRoundEndTime(startTime17);
		maps.put("round17", getRotationStatistics2(startTime17, endTime17));
		// 第18轮次
		Date startTime18 = DateUtils.getNextDay(endTime17);
		Date endTime18 = DateUtils.getRoundEndTime(startTime18);
		maps.put("round18", getRotationStatistics2(startTime18, endTime18));
		// 第19轮次
		Date startTime19 = DateUtils.getNextDay(endTime18);
		Date endTime19 = DateUtils.getRoundEndTime(startTime19);
		maps.put("round19", getRotationStatistics2(startTime19, endTime19));
		// 第20轮次
		Date startTime20 = DateUtils.getNextDay(endTime19);
		Date endTime20 = DateUtils.getRoundEndTime(startTime20);
		maps.put("round20", getRotationStatistics2(startTime20, endTime20));
		// 第21轮次
		Date startTime21 = DateUtils.getNextDay(endTime20);
		Date endTime21 = DateUtils.getRoundEndTime(startTime21);
		maps.put("round21", getRotationStatistics2(startTime21, endTime21));
		// 第22轮次
		Date startTime22 = DateUtils.getNextDay(endTime21);
		Date endTime22 = DateUtils.getRoundEndTime(startTime22);
		maps.put("round22", getRotationStatistics2(startTime22, endTime22));
		// 第23轮次
		Date startTime23 = DateUtils.getNextDay(endTime22);
		Date endTime23 = DateUtils.getRoundEndTime(startTime23);
		maps.put("round23", getRotationStatistics2(startTime23, endTime23));
		// 第24轮次
		Date startTime24 = DateUtils.getNextDay(endTime23);
		Date endTime24 = DateUtils.getRoundEndTime(startTime24);
		maps.put("round24", getRotationStatistics2(startTime24, endTime24));
		// 第25轮次
		Date startTime25 = DateUtils.getNextDay(endTime24);
		Date endTime25 = DateUtils.getRoundEndTime(startTime25);
		maps.put("round25", getRotationStatistics2(startTime25, endTime25));
		// 第26轮次
		Date startTime26 = DateUtils.getNextDay(endTime25);
		Date endTime26 = DateUtils.getRoundEndTime(startTime26);
		Date endDay = DateUtils.getAnyDayAnyYearAnyMonth(new Date(), 0, 11, 31);
		maps.put("round26", getRotationStatistics2(startTime26, endDay));
		// 返回26轮剩余的时间
		Date startTime27 = DateUtils.getNextDay(endTime26);
		// 如果是闰年
		if (DateUtils.getLeapYear(new Date())) {
			Date endTime27 = DateUtils.getRoundTime(startTime27, 1);
			Integer eachRoundTotal = gjzLcMapper.getEachRoundTotal(DateUtils.getSimpleDateFormat(startTime27),
					DateUtils.getSimpleDateFormat(endTime27));
			// if (eachRoundTotal == 0 || eachRoundTotal == null) {
			countRoundMonth.put("eachRoundTotal", eachRoundTotal);
			// }

			for (int i = 0; i < 2; i++) {
				Results result = new Results();
				String date = DateUtils.getSimpleDateFormat(DateUtils.getRoundTime(startTime27, i));
				Integer dayPlasmaGross = gjzLcMapper.pulpQuantityDetailRound(date);
				// if (dayPlasmaGross == null || dayPlasmaGross == 0) {
				result.setDate(date);
				result.setCount(dayPlasmaGross);
				// 每轮每天血浆的总量
				roundCountDay.put("day" + String.valueOf(i + 1), result);
				// }
			}
			plasma.setRoundCountDay(roundCountDay);
			plasma.setCountRoundMonth(countRoundMonth);
			maps.put("round27", plasma);
		} else {
			// 如果不是闰年
			Date endTime27 = startTime27;
			Integer eachRoundTotal = gjzLcMapper.getEachRoundTotal(DateUtils.getSimpleDateFormat(startTime27),
					DateUtils.getSimpleDateFormat(endTime27));
			if (eachRoundTotal == 0 || eachRoundTotal == null) {
				countRoundMonth.put("eachRoundTotal", 0);
				Results result = new Results();
				Integer dayPlasmaGross = gjzLcMapper
						.pulpQuantityDetailRound(DateUtils.getSimpleDateFormat(startTime27));
				// if (dayPlasmaGross == null || dayPlasmaGross == 0) {
				result.setDate(DateUtils.getSimpleDateFormat(startTime27));
				result.setCount(dayPlasmaGross);
				// 每轮每天血浆的总量
				roundCountDay.put("day1", result);
				plasma.setRoundCountDay(roundCountDay);
				maps.put("round27", plasma);
				// }

			}

		}
		// }
		// 添加到缓存中
		jedisClient.set("JSON2", JSONObject.toJSONString(maps));
		return maps;

	}

	/**
	 * 统计浆员的主要来源的方法
	 */
	@SuppressWarnings("unchecked")
	@Override
	public Map<String, Results> getPlasmaSourceMember() throws Exception {
		Map<String, Results> result = new HashMap<String, Results>();
		// 先查询缓存
		String JSON3 = jedisClient.get("JSON3");
		if (StringUtil.isNotNull(JSON3)) {
			result = (Map<String, Results>) JSONObject.parse(JSON3);
			return result;
		}
		result = insertPlasmaSourceMember();
		// 添加到缓存中
		jedisClient.set("JSON3", JSONObject.toJSONString(result));
		return result;
	}

	/**
	 * 根据职业统计浆员
	 */
	private Map<String, Integer> getPlasmaStatisticsByMetier(String startTime18, String endTime18) throws Exception {
		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		Map<String, Integer> metiers = new LinkedHashMap<String, Integer>();
		String[] str = { ValueUtiles.STUDENT, ValueUtiles.FARMERS, ValueUtiles.LEADER, ValueUtiles.SOLDIER,
				ValueUtiles.WORKER, ValueUtiles.FREELANCE };
		String[] str2 = { "student", "farmers", "leader", "soldier", "worker", "freelance" };
		for (int i = 0; i <= 5; i++) {
			metiers.put(str2[i], plasmaCountMapper.getPlasmaStatisticsByMetier(str[i], startTime18, endTime18));
			logger.info(str2[i] + "===============>>"
					+ plasmaCountMapper.getPlasmaStatisticsByMetier(str[i], startTime18, endTime18));
		}
		int other1 = plasmaCountMapper.getPlasmaStatisticsByOther1(startTime18, endTime18);
		int other2 = plasmaCountMapper.getPlasmaStatisticsByOther2(startTime18, endTime18);
		int other = other1 + other2;
		metiers.put("other", other);
		logger.info("other" + "===============>>" + other);
		return metiers;

	};

	/**
	 * 根据性别统计浆员
	 */
	private Map<String, Integer> getPlasmaStatisticsByGender(String startTime1, String endTime1) throws Exception {
		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		String[] sex = { ValueUtiles.MALE, ValueUtiles.FEMALE };
		String[] index = { "male", "female" };
		Map<String, Integer> genders = new HashMap<String, Integer>();
		// male 男； female 女
		for (int i = 0; i <= 1; i++) {

			genders.put(index[i], plasmaCountMapper.getPlasmaStatisticsByGender(sex[i], startTime1, endTime1));
			logger.info(index[i] + "===============>>"
					+ plasmaCountMapper.getPlasmaStatisticsByGender(sex[i], startTime1, endTime1));
		}

		return genders;
	}

	/**
	 * 根据年龄统计浆员
	 */
	private Map<String, Integer> getPlasmaStatisticsByAge(String startTime1, String endTime1) throws Exception {
		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		Map<String, Integer> ages = new LinkedHashMap<String, Integer>();
		Date date = new Date();
		// 1998-01-01=========2000-12-31
		String startTime98 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -20, 0, 1);
		String endTime20 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -18, 11, 31);
		// System.out.println(startTime98 + "=========" + endTime20);
		// 1988-01-01=========1997-12-31
		String startTime88 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -30, 0, 1);
		String endTime97 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -21, 11, 31);
		// System.out.println(startTime88 + "=========" + endTime97);
		// 1978-01-01=========1987-12-31
		String startTime78 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -40, 0, 1);
		String endTime87 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -31, 11, 31);
		// System.out.println(startTime78 + "=========" + endTime87);
		// 1968-01-01=========1977-12-31
		String startTime68 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -50, 0, 1);
		String endTime77 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -41, 11, 31);
		// System.out.println(startTime68 + "=========" + endTime77);
		// 1964-01-01=========1967-12-31
		String startTime64 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -54, 0, 1);
		String endTime67 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -51, 11, 31);
		// System.out.println(startTime64 + "=========" + endTime67);
		// 1963-01-01=========1963-12-31
		String startTime63 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -55, 0, 1);
		String endTime63 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -55, 11, 31);
		// 大于55岁的浆员
		String endTime = DateUtils.getAnyDayAnyYearAnyMonthString(date, -56, 11, 31);
		// System.out.println(startTime63 + "=========" + endTime63);
		// 18-20岁 21-30岁 31-40岁 41-50岁 51-54岁 2017年55岁

		int age1 = plasmaCountMapper.getPlasmaStatisticsByAge(startTime98, endTime20, startTime1, endTime1);
		ages.put("age18-20", age1);
		logger.info("18-20岁" + "===============>>" + age1);
		int age2 = plasmaCountMapper.getPlasmaStatisticsByAge(startTime88, endTime97, startTime1, endTime1);
		ages.put("age21-30", age2);
		logger.info("21-30岁 " + "===============>>" + age2);
		int age3 = plasmaCountMapper.getPlasmaStatisticsByAge(startTime78, endTime87, startTime1, endTime1);
		ages.put("age31-40", age3);
		logger.info("31-40岁 " + "===============>>" + age3);
		int age4 = plasmaCountMapper.getPlasmaStatisticsByAge(startTime68, endTime77, startTime1, endTime1);
		ages.put("age41-50", age4);
		logger.info("41-50岁 " + "===============>>" + age4);
		int age5 = plasmaCountMapper.getPlasmaStatisticsByAge(startTime64, endTime67, startTime1, endTime1);
		ages.put("age51-54", age5);
		logger.info("51-54岁 " + "===============>>" + age5);
		int age6 = plasmaCountMapper.getPlasmaStatisticsByAge(startTime63, endTime63, startTime1, endTime1);
		ages.put("age55", age6);
		logger.info("2017年55岁 " + "===============>>" + age6);
		int age7 = plasmaCountMapper.getPlasmaStatisticsByOtherAge(endTime, startTime1, endTime1);
		ages.put("age55up", age7);
		logger.info("55岁以上 " + "===============>>" + age7);

		return ages;
	}

	/**
	 * 定时写入redis缓存中
	 */
	@Override
	public Map<String, Results> insertPlasmaSourceMember() throws Exception {
		Map<String, Results> result = new LinkedHashMap<String, Results>();
		String startTime18 = DateUtils.getAnyDayAnyYearAnyMonthString(new Date(), 0, 0, 1);
		for (int i = 0; i <= 11; i++) {
			Results rs = new Results();
			String endTime18 = DateUtils.getMonthLastDay(new Date(), 0, i);
			String startTime = DateUtils.getAnyDayAnyYearAnyMonthString(new Date(), 0, i, 1);
			// 每个月累加的
			rs.getMaps().put("Metier", getPlasmaStatisticsByMetier(startTime18, endTime18));
			rs.getMaps().put("Gender", getPlasmaStatisticsByGender(startTime18, endTime18));
			rs.getMaps().put("Age", getPlasmaStatisticsByAge(startTime18, endTime18));
			// 每个月的
			rs.getMaps2().put("Metier", getPlasmaStatisticsByMetier(startTime, endTime18));
			rs.getMaps2().put("Gender", getPlasmaStatisticsByGender(startTime, endTime18));
			rs.getMaps2().put("Age", getPlasmaStatisticsByAge(startTime, endTime18));
			result.put("month" + String.valueOf(i + 1), rs);
		}
		// 添加到缓存中
		jedisClient.set("JSON3", JSONObject.toJSONString(result));
		return result;
	}

	/**
	 * 饼图统计浆员
	 */
	@Override
	public Map<String, Map<String, Integer>> getPlasmaCountByPieChart(String date1) throws Exception {
		Integer dateTiem = Integer.parseInt(date1) - 1;
		Date date = new Date();
		String startTime18 = DateUtils.getAnyDayAnyYearAnyMonthString(date, 0, dateTiem, 1);
		String endTime18 = DateUtils.getMonthLastDay(date, 0, dateTiem);
		Map<String, Map<String, Integer>> results = getPlasmaCountClassifications(date, startTime18, endTime18);
		return results;
	}

	/**
	 * 按职业分类统计浆员的主要来源
	 */
	private Map<String, Map<String, Integer>> getPlasmaCountClassifications(Date date, String startTime18,
			String endTime18) throws Exception {
		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		Map<String, Map<String, Integer>> metiers = new HashMap<String, Map<String, Integer>>();
		String startTime98 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -20, 0, 1);
		String endTime20 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -18, 11, 31);
		// System.err.println(startTime98 + "=========" + endTime20);
		// 1988-01-01=========1997-12-31
		String startTime88 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -30, 0, 1);
		String endTime97 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -21, 11, 31);
		// System.err.println(startTime88 + "=========" + endTime97);
		// 1978-01-01=========1987-12-31
		String startTime78 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -40, 0, 1);
		String endTime87 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -31, 11, 31);
		// System.err.println(startTime78 + "=========" + endTime87);
		// 1968-01-01=========1977-12-31
		String startTime68 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -50, 0, 1);
		String endTime77 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -41, 11, 31);
		// System.err.println(startTime68 + "=========" + endTime77);
		// 1964-01-01=========1967-12-31
		String startTime64 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -54, 0, 1);
		String endTime67 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -51, 11, 31);
		// System.err.println(startTime64 + "=========" + endTime67);
		// 1963-01-01=========1963-12-31
		String startTime63 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -55, 0, 1);
		String endTime63 = DateUtils.getAnyDayAnyYearAnyMonthString(date, -55, 11, 31);
		String endTime = DateUtils.getAnyDayAnyYearAnyMonthString(date, -56, 11, 31);
		//
		// System.err.println(startTime63 + "=========" + endTime63);
		// 18-20岁 21-30岁 31-40岁 41-50岁 51-54岁 2017年55岁
		String[] metier = { ValueUtiles.STUDENT, ValueUtiles.FARMERS, ValueUtiles.LEADER, ValueUtiles.SOLDIER,
				ValueUtiles.WORKER, ValueUtiles.FREELANCE };
		String[] str2 = { "student", "farmers", "leader", "soldier", "worker", "freelance" };
		String[] str3 = { startTime98, startTime88, startTime78, startTime68, startTime64, startTime63 };
		String[] str4 = { endTime20, endTime97, endTime87, endTime77, endTime67, endTime63 };
		String[] str5 = { "age18-20", "age21-30", "age31-40", "age41-50", "age51-54", "age55" };

		for (int i = 0; i <= 5; i++) {
			Map<String, Integer> maps = new HashMap<String, Integer>();
			// age18-20
			int age = plasmaCountMapper.getPlasmaCountClassifications(metier[i], startTime98, endTime20, startTime18,
					endTime18);
			logger.info(metier[i] + ":" + str5[i] + "===============>>" + age + "人");
			maps.put("age18-20", age);
			// age21-30
			int age2 = plasmaCountMapper.getPlasmaCountClassifications(metier[i], startTime88, endTime97, startTime18,
					endTime18);
			logger.info(metier[i] + ":" + str5[i] + "===============>>" + age2 + "人");
			maps.put("age21-30", age2);
			// age31-40
			int age3 = plasmaCountMapper.getPlasmaCountClassifications(metier[i], startTime78, endTime87, startTime18,
					endTime18);
			logger.info(metier[i] + ":" + str5[i] + "===============>>" + age3 + "人");
			maps.put("age31-40", age3);
			// age41-50
			int age4 = plasmaCountMapper.getPlasmaCountClassifications(metier[i], startTime68, endTime77, startTime18,
					endTime18);
			logger.info(metier[i] + ":" + str5[i] + "===============>>" + age4 + "人");
			maps.put("age41-50", age4);
			// age51-54
			int age5 = plasmaCountMapper.getPlasmaCountClassifications(metier[i], startTime64, endTime67, startTime18,
					endTime18);
			logger.info(metier[i] + ":" + str5[i] + "===============>>" + age5 + "人");
			maps.put("age51-54", age5);
			// age55
			int age6 = plasmaCountMapper.getPlasmaCountClassifications(metier[i], startTime63, endTime63, startTime18,
					endTime18);
			logger.info(metier[i] + ":" + str5[i] + "===============>>" + age6 + "人");
			int age7 = plasmaCountMapper.getOtherJobCount(metier[i], endTime, startTime18, endTime18);
			logger.info(metier[i] + ":" + "超过55岁" + "===============>>" + age7 + "人");
			maps.put("age55", age6);
			maps.put("age55up", age7);
			metiers.put(str2[i], maps);
		}
		// 其他职业超过55岁的
		int other1 = plasmaCountMapper.getPlasmaCountClassificationsByOther1(endTime, startTime18, endTime18);
		int other2 = plasmaCountMapper.getPlasmaCountClassificationsByOther2(endTime, startTime18, endTime18);
		// 超过55岁的
		int otherAge = other1 + other2;
		Map<String, Integer> map = new HashMap<String, Integer>();
		for (int i = 0; i <= 5; i++) {
			int num = plasmaCountMapper.getOtherProfessionalCount(str3[i], str4[i], startTime18, endTime18);
			int num2 = plasmaCountMapper.getOtherProfessionalCount2(str3[i], str4[i], startTime18, endTime18);
			int num3 = num + num2;
			map.put(str5[i], num3);
			map.put("age55up", otherAge);
			metiers.put("otherJob", map);
		}
		return metiers;

	}

	/**
	 * 浆员的综合统计结果
	 * 
	 * @throws Exception
	 * 
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<Map<String, Map<String, FrequencyResult>>> getPlasmaComprehensiveStatisticsResult() throws Exception {
		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		List<Map<String, Map<String, FrequencyResult>>> result = new ArrayList<Map<String, Map<String, FrequencyResult>>>();
		Map<String, Map<String, FrequencyResult>> map1 = new LinkedHashMap<String, Map<String, FrequencyResult>>();
		Map<String, Map<String, FrequencyResult>> map2 = new LinkedHashMap<String, Map<String, FrequencyResult>>();
		// 先查询缓存currentYearFrequency lastYearFrequency
		String lastYearFrequency = jedisClient.get("lastYearFrequency");
		String currentYearFrequency = jedisClient.get("currentYearFrequency");
		if (StringUtil.isNotNull(lastYearFrequency) && StringUtil.isNotNull(currentYearFrequency)) {
			map1 = (Map<String, Map<String, FrequencyResult>>) JSONObject.parse(lastYearFrequency);
			map2 = (Map<String, Map<String, FrequencyResult>>) JSONObject.parse(currentYearFrequency);
			result.add(map1);
			result.add(map2);
			return result;
		}
		result.add(getPlasmaComprehensiveStatisticsResult2());
		result.add(getCurrentYearFrequencyStatistics());
		return result;
	}

	/**
	 * 得到浆员的卡号
	 */
	private String getProviderNo(List<Integer> list) throws Exception {
		StringBuilder sb = new StringBuilder();
		for (Integer id : list) {
			sb.append("'" + id + "'" + ",");
		}
		return sb.substring(0, sb.length() - 1);
	}

	/**
	 * 当前月进站人数的浆量总和
	 */
	public int getTowTimesPlasma(String startTime, String endTime) throws Exception {
		List<Integer> returnPulp = new ArrayList<Integer>();
		List<Results> lists = plasmaCountMapper.getClassifyStatisticsRsults(startTime, endTime);
		for (Results rs : lists) {
			// 把每个月献浆大于2次的人取出来
			if (rs.getTotal() > 1) {
				returnPulp.add(rs.getProviderNo());
			}
		}
		if (StringUtil.isNotNull(returnPulp)) {
			String ProviderNo = getProviderNo(returnPulp);
			// 返站浆员的浆量
			int returnPulpAmount = plasmaCountMapper.getPlasmaReturnStand(ProviderNo, startTime, endTime);
			return returnPulpAmount;
		}

		return 0;

	}

	/**
	 * 当月新浆员进站人数
	 */
	public int getTowTimesPerson(String startTime, String endTime) {
		List<Integer> returnPulp = new ArrayList<Integer>();
		List<Results> lists = plasmaCountMapper.getClassifyStatisticsRsults(startTime, endTime);
		for (Results rs : lists) {
			// 把每个月献浆大于2次的人取出来
			if (rs.getTotal() > 1) {
				returnPulp.add(rs.getProviderNo());
			}
		}
		// 返站的人数
		return returnPulp.size();
	}

	/**
	 * 16-17的频次的逻辑
	 */
	public FrequencyResult getNumberRegistrationsPerMonth(FrequencyResult fr, Integer year, Integer month,
			String startTime2, String endTime2) throws Exception {
		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		List<List<String>> result = new ArrayList<List<String>>();
		for (int i = 0; i <= month - 1; i++) {
			List<String> list = new ArrayList<String>();
			String startTime = DateUtils.getAnyDayAnyYearAnyMonthString(new Date(), year, i, 1);
			String endTime = DateUtils.getMonthLastDay(new Date(), year, i);
			// 每个月的新建档人数
			List<Integer> newPulp = plasmaCountMapper.getNumberRegistrationsPerMonth(startTime, endTime);
			String ProviderNo = getProviderNo(newPulp);
			list.add(ProviderNo);
			result.add(list);
		}
		int returnPulpTotal = 0;
		int returnPulpAmountTotal = 0;
		Map<String, Integer> map3 = new LinkedHashMap<String, Integer>();
		Map<String, Integer> map4 = new LinkedHashMap<String, Integer>();
		for (int i = 0; i <= result.size() - 1; i++) {
			Map<String, Integer> map1 = new LinkedHashMap<String, Integer>();
			Map<String, Integer> map2 = new LinkedHashMap<String, Integer>();
			int a = plasmaCountMapper.getPlasmaIntervalStatistics(result.get(i).get(0), startTime2, endTime2);
			returnPulpTotal += a;
			// 上月的新浆员在本月进站的总人数
			map1.put("month" + (i + 1), a);
			// 上月的新浆员在本月进站的总浆量
			int b = plasmaCountMapper.getPlasmaReturnStand(result.get(i).get(0), startTime2, endTime2);
			returnPulpAmountTotal += b;
			map2.put("month" + (i + 1), b);
			fr.getReturnPulp().add(map1);
			fr.getReturnPulpAmount().add(map2);
			// System.err.println("month" + (i + 1) + "========>>" + result.get(i).get(0));
			// System.err.println(result.size());
		}
		int currentMan = getTowTimesPerson(startTime2, endTime2);
		int currentPlasma = getTowTimesPlasma(startTime2, endTime2);
		fr.setReturnPulpTotal(returnPulpTotal + currentMan);
		fr.setReturnPulpAmountTotal(returnPulpAmountTotal + (currentPlasma - currentMan));

		// 本月第二次進站的人數
		map3.put("month" + (month + 1), currentMan);
		// list1.add(map3);
		// 本月二次進站的漿量
		map4.put("month" + (month + 1), currentPlasma - currentMan);
		fr.getReturnPulp().add(map3);
		fr.getReturnPulpAmount().add(map4);
		List<Integer> newPulp2 = plasmaCountMapper.getRegisteredOfMonthPlasma(startTime2, endTime2);
		fr.setNewPulp(newPulp2.size());
		return fr;
	}

	// 18年的逻辑
	public FrequencyResult getNumberRegistrationsPerMonth3(FrequencyResult fr, Integer month, String startTime2,
			String endTime2) throws Exception {
		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		List<List<String>> result = new ArrayList<List<String>>();
		// 7月
		for (int i = 1; i <= month; i++) {
			List<String> list = new ArrayList<String>();
			String startTime = DateUtils.getAnyDayAnyYearAnyMonthString(new Date(), 0, i, 1);
			String endTime = DateUtils.getMonthLastDay(new Date(), 0, i);
			// 每个月的新建档人数
			List<Integer> newPulp = plasmaCountMapper.getNumberRegistrationsPerMonth(startTime, endTime);
			if (StringUtil.isNotNull(newPulp)) {
				String ProviderNo = getProviderNo(newPulp);
				list.add(ProviderNo);
				result.add(list);
			}

		}
		int returnPulpTotal = 0;
		int returnPulpAmountTotal = 0;
		Map<String, Integer> map3 = new LinkedHashMap<String, Integer>();
		Map<String, Integer> map4 = new LinkedHashMap<String, Integer>();
		for (int i = 0; i <= result.size() - 1; i++) {
			Map<String, Integer> map1 = new LinkedHashMap<String, Integer>();
			Map<String, Integer> map2 = new LinkedHashMap<String, Integer>();
			// 上月的新浆员在本月进站的总人数
			int a = plasmaCountMapper.getPlasmaIntervalStatistics(result.get(i).get(0), startTime2, endTime2);
			returnPulpTotal += a;
			map1.put("month" + (i + 1), a);
			// 上月的新浆员在本月进站的总浆量
			int b = plasmaCountMapper.getPlasmaReturnStand(result.get(i).get(0), startTime2, endTime2);
			returnPulpAmountTotal += b;
			map2.put("month" + (i + 1), b);
			fr.getReturnPulp().add(map1);
			fr.getReturnPulpAmount().add(map2);

			System.err.println(result.size());
		}
		int currentMan = getTowTimesPerson(startTime2, endTime2);
		// 本月第二次進站的人數
		map3.put("month" + (month + 1), currentMan);
		// 本月二次進站的漿量
		int currentPlasma = getTowTimesPlasma(startTime2, endTime2);
		map4.put("month" + (month + 1), currentPlasma - currentMan);
		List<Integer> newPulp2 = plasmaCountMapper.getRegisteredOfMonthPlasma(startTime2, endTime2);
		fr.setReturnPulpTotal(returnPulpTotal + currentMan);
		fr.setReturnPulpAmountTotal(returnPulpAmountTotal + (currentPlasma - currentMan));
		fr.setNewPulp(newPulp2.size());
		fr.getReturnPulp().add(map3);
		fr.getReturnPulpAmount().add(map4);
		return fr;
	}

	/**
	 * 2016-2017的频次
	 */
	@Override
	public Map<String, Map<String, FrequencyResult>> getPlasmaComprehensiveStatisticsResult2() throws Exception {
		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		Map<String, Map<String, FrequencyResult>> result = new LinkedHashMap<String, Map<String, FrequencyResult>>();
		Date date = new Date();
		// 2016年
		Map<String, FrequencyResult> year2016 = new LinkedHashMap<String, FrequencyResult>();
		for (int i = 0; i <= 11; i++) {
			String startTime = DateUtils.getAnyDayAnyYearAnyMonthString(date, -2, i, 1);
			String endTime = DateUtils.getMonthLastDay(date, -2, i);
			FrequencyResult fr = new FrequencyResult();
			year2016.put("month" + (i + 1), getNumberRegistrationsPerMonth(fr, -2, i, startTime, endTime));
		}
		// 2017年
		Map<String, FrequencyResult> year2017 = new LinkedHashMap<String, FrequencyResult>();
		for (int i = 0; i <= 11; i++) {
			String startTime = DateUtils.getAnyDayAnyYearAnyMonthString(date, -1, i, 1);
			String endTime = DateUtils.getMonthLastDay(date, -1, i);
			FrequencyResult fr = new FrequencyResult();
			year2017.put("month" + (i + 1), getNumberRegistrationsPerMonth(fr, -1, i, startTime, endTime));
		}
		result.put("year2016", year2016);
		result.put("year2017", year2017);

		// 添加到缓存
		// 添加到缓存中
		jedisClient.set("lastYearFrequency", JSONObject.toJSONString(result));
		return result;
	}

	/**
	 * 2018年频次
	 */
	@Override
	public Map<String, Map<String, FrequencyResult>> getCurrentYearFrequencyStatistics() throws Exception {
		DataSourceContextHolder.setDataSourceType(DataSourceConst.jingying);
		Map<String, Map<String, FrequencyResult>> result = new LinkedHashMap<String, Map<String, FrequencyResult>>();
		Date date = new Date();
		Integer month = 0;
		// 得到当前月的具体时间
		Map<String, FrequencyResult> year2018 = new LinkedHashMap<String, FrequencyResult>();
//		for (int i = 0; i <= 11; i++) {
//			String startTime = DateUtils.getAnyDayAnyYearAnyMonthString(date, 0, i, 1);
//			String endTime = DateUtils.getMonthLastDay(date, 0, i);
//			List<Results> lists = plasmaCountMapper.getClassifyStatisticsRsults(startTime, endTime);
//			 System.err.println(startTime+"====================="+endTime);
//		   
//			for (Results rs : lists) {
//				if (DateUtils.getYesterdayTime(date, 0).equals(DateUtils.getSimpleDateFormat(rs.getFileDate()))) {
//					month = DateUtils.getNumber(DateUtils.getYesterdayTime(date, 1));
//				}
//				try {
//					if (DateUtils.getDayOfWeek(DateUtils.getYesterdayTime(date, 1))) {
//						month = DateUtils.getNumber(DateUtils.getYesterdayTime(date, 2));
//					}
//				} catch (Throwable e) {
//					e.printStackTrace();
//				}
//			}
//		}
		month = DateUtils.getNumber(DateUtils.getSimpleDateFormat(new Date()));
		for (int i = 0; i <= month - 1; i++) {
			FrequencyResult fr = new FrequencyResult();
			String startTime = DateUtils.getAnyDayAnyYearAnyMonthString(date, 0, i, 1);
			String endTime = DateUtils.getMonthLastDay(date, 0, i);
			year2018.put("month" + (i + 1), getNumberRegistrationsPerMonth3(fr, i, startTime, endTime));
		}
		result.put("year2018", year2018);
		// 添加到缓存中
		// 添加到缓存中
		jedisClient.set("currentYearFrequency", JSONObject.toJSONString(result));
		return result;

	}
}
